package edu.wpi.cs509.ui.simulators;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.TimerTask;

import edu.wpi.cs509.ui.intfc.ClientLogicNotify;
import edu.wpi.cs509.ui.intfc.PlayerStatsInterface;

public class LeaderboardNotfiy extends TimerTask {

	private Random R = new Random();
	private ClientLogicNotify ui;
	private String username = null;
	
	private int rank = -1;
	private int count;
	
	public LeaderboardNotfiy(ClientLogicNotify ui, int rank, int count) {
		this.ui = ui;
		this.rank = rank;
		this.count = count;
	}

	public LeaderboardNotfiy(ClientLogicNotify ui, String username, int count) {
		this.ui = ui;
		this.username = username;
		this.count = count;
	}

	@Override
	public void run() {
		List<PlayerStatsInterface> leaderboard = new ArrayList<PlayerStatsInterface>();
		
		int totalPlayers = R.nextInt(1000);
		
		int i = count;
		if (username != null) {
			leaderboard.add( 
					new PlayerStats(username, R.nextInt(500), R.nextInt(500), R.nextInt(100)) );
			i--;

			do {
				leaderboard.add( 
						new PlayerStats(Username.nextUsername(), 
								R.nextInt(500), R.nextInt(500), R.nextInt(100)) );
				i--;
			} while (i>0);
		} else {
			int r = rank;
			do {
				leaderboard.add( 
						new PlayerStats(Username.nextUsername(), 
								R.nextInt(500), R.nextInt(500), r++) );
				i--;
			} while (i>0);
		}
		
		ui.notifyLeaderBoard(leaderboard, rank, totalPlayers);
	}

}
